
#!/usr/bin/python3
# coding=utf-8
#
# Copyright (C) 2025.
# Huawei Technologies Co., Ltd. All rights reserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# ===============================================================================

import numpy as np

dtype_emu = {np.float16: 1, np.float32: 0}


def gen_lp_norm_v2_data():
    # 配置输入
    dtype = np.float32
    input_shape = [11,123]  # 可以随意修改测试
    axis = 1                # 0=全局, 1=列规约, 2=行规约
    p_value = -1.0            # 无穷大范数

    rows, cols = input_shape

    # 随机输入数据
    input_x = np.random.uniform(-10, 10, input_shape).astype(dtype)

    # Golden 计算
    if p_value == -1.0:
        # 全局范数
        norm = np.linalg.norm(input_x, ord=np.inf, axis=0, keepdims=True)
        # norm = np.linalg.norm(input_x.reshape(-1), ord=np.inf)
        golden = input_x / norm
    elif axis == 0:
        # 全局范数
        norm = np.linalg.norm(input_x.reshape(-1), ord=p_value)
        golden = input_x / norm
    elif axis == 1:
        # 按列规约 (axis=1 → 每列归一化)
        norm = np.linalg.norm(input_x, ord=p_value, axis=0, keepdims=True)
        golden = input_x / norm
    elif axis == 2:
        # 按行规约 (axis=2 → 每行归一化)
        norm = np.linalg.norm(input_x, ord=p_value, axis=1, keepdims=True)
        golden = input_x / norm
    
    else:
        raise ValueError("Unsupported axis = {}".format(axis))


    # 保存文件
    input_x.tofile("./input/input_x.bin")
    golden.astype(dtype).tofile("./output/golden.bin")

    print("✅ Data generated:")
    print("expect pnorm :",norm)
    print(" - input_x.bin shape:", input_x.shape, input_x.dtype)
    print(" - golden.bin shape:", golden.shape, golden.dtype)

if __name__ == "__main__":
    gen_lp_norm_v2_data()


